<?php
/**
 * Bootstrap class
 * @author vsemaphore
 * @version $Id: Bootstrap.php 280 2009-07-08 11:08:24Z nazin $
 */
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{ 
	
	public function run() {
		$__ts = microtime(true); 
		$front = Zend_Controller_Front::getInstance();
        $front->setControllerDirectory(dirname(__FILE__).'/controllers');
		
        
        $config = Zend_Registry::get('config');
        $dbOptions = $config->database;
        
        $db = new Zend_Db_Adapter_Pdo_Mysql(array(
    			'host'     => $dbOptions->host,
    			'username' => $dbOptions->user,
    			'password' => $dbOptions->password,
    			'dbname'   => $dbOptions->database,
        		'unix_socket'	=> $dbOptions->unix_socket,
			));
        
		Zend_Registry::set('db', $db);
        
      	try {
	      	//Zend_Registry::set('DoctrineConnection', $conn);
	        $front->setParam('bootstrap', $this);
	        
	        /**
	         * FrontController plugins
	         */
	        
	        $plugins = $config->frontcontroller->plugins;
	         
	        if($plugins instanceof Zend_Config) {
	        	foreach ($plugins as $plugin) {
	        		@list($name, $priority) = explode('@', $plugin);
	        		
	        		if($priority)
	        			$front->registerPlugin(new $name, $priority);
	        		else
	        			$front->registerPlugin(new $name);
	        	}
	        }
	        
	        $front->dispatch();
	        
//        	$conn->commit();
      	} catch (Exception $e) {
//      		$conn->rollback();
      		throw $e;	
      	}
      	
		$__p = microtime(true) - $__ts; 
		//echo "[$__p]";        
	}

}

